package com.doitedu.mr.day06;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @Date 2021/12/7
 * @Created by HANGGE
 * @Description TODO
 */
public class NoReducer {
    static  class  NoReducerMapper extends Mapper<LongWritable , Text , Text, NullWritable>{
         Text k = new  Text() ;
        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            String str = value.toString().toUpperCase();
            k.set(str);
            context.write(k,NullWritable.get());
        }
    }

    public static void main(String[] args) throws  Exception {
        // Job  统计文件中单词出现的次数
        Configuration conf = new Configuration();
        // 1  创建 JOB
        Job job = Job.getInstance(conf, "no_reducer");
        // 1) Mapper 类
        job.setMapperClass(NoReducerMapper.class);

        // 4)  设置reduce输出的数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        // 5) 设置输入的数据路径
        FileInputFormat.setInputPaths(job , new Path("d://word.txt"));
        // 6) 设置输出的结果保存路径
        FileOutputFormat.setOutputPath(job, new Path("d://upper/"));
        // 2 提交工作
        // 等待执行完成 , 打印执行过
        job.waitForCompletion(true) ;
    }
}
